#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

#define DEBUG
#ifndef DEBUG
	#define ASSERT(x)
#else
	#define ASSERT(x) \
		if(! (x)) \
		{\
			cout << "Failed at: " << #x << endl; \
			cout << "On line: " << __LINE__ << endl; \
			cout << "In file: " << __FILE__ << endl; \
			abort(); \
		}
#endif

typedef vector <int> IVEC;

class picture {
	public:
		void pad(int , int); // padding
		void rot(int); // rotate

		vector <IVEC> p;
		int rows;
		int cols;
};

void picture::pad(int w, int pv)
{
	int i, j, k;
	vector <IVEC> tmp;

	ASSERT(w >= 0);
	ASSERT(pv >= 0 && pv <= 255);
	tmp.resize(p.size() + 2 * w);
	for(i = 0; i < w; i++)
	{
		for(j = 0; j < p[0].size() + (w * 2); j++)
		{
			tmp[i].push_back(pv);
		}
	}
	k = 0;
	for(i = w; i < p.size() + w; i++)
	{
		for(j = 0; j < w; j++)
		{
			tmp[i].push_back(pv);
		}
		for(j = 0; j < p[0].size(); j++)
		{
			tmp[i].push_back(p[k][j]);
		}
		for(j = 0; j < w; j++)
		{
			tmp[i].push_back(pv);
		}
		k++;
	}
	for(i = w + p.size(); i < p.size() + (w * 2); i++)
	{
		for(j = 0; j < p[0].size() + (2 * w); j++)
		{
			tmp[i].push_back(pv);
		}
	}

	p = tmp;
}

void picture::rot(int leftOrRight)
{
	cout << "Rotating\n";
	vector <IVEC> tmp[cols][rows];
	//first row-->last col
	if(leftOrRight==1){

		for(int i=rows-1;i>=0;i--){
			tmp.pushback(vector<int>())
			for(int k=cols-1;k>=0;k--){
				cout << "Pushing back " << p[i][k] << endl;
				tmp[i].push_back(p[i][k]);
			}
		}

	}
	//first row-->first col
	else{
	}


	p=tmp;






}

main(int argc, char **argv)
{
	int i, c, r, j, v, w, pv;
	string s;
	picture *pp;

	// --------------- INITIALIZATION ------------------
	pp = new picture;
	if (!(cin >> s)) {cerr << "Empty file." << endl;  exit(1);}
	if (s != "P2") {cerr << "First word is not P2." << endl; exit(1);}
	if (!(cin >> c) || c <= 0) {cerr << "Bad column spec." << endl; exit(1);}
	if (!(cin >> r) || r <= 0) {cerr << "Bad column spec." << endl; exit(1);}
	if (!(cin >> i) || i != 255) {cerr << "Bad spec of 255." << endl; exit(1);}
	pp -> p.resize(r);
	for (i = 0; i < r; i++) for (j = 0; j < c; j++) {
		if (!(cin >> v) || v < 0 || v > 255) {cerr << "Bad pixel." << endl; exit(1);}
		pp -> p[i].push_back(v);
	}
	if (cin >> s) {cerr << "Extra stuff at the end of the file." << endl; exit(1);}
	pp->rows=pp->p.size();
	pp->cols=pp->p[0].size();
	// -------------------------------------------------

	s = argv[1];
	if(s == "Pad")
	{
		w = atoi(argv[2]);
		pv = atoi(argv[3]);
		pp -> pad(w, pv);
	}
	else if(s=="Rot"){
		w = atoi(argv[2]);
		pp->rot(w);
	}
	/*
	else if{
	}
	else if{
	}
	else if{
	}
*/




	/* -------------- PRINT ---------------*/
	for(i = 0; i < pp -> p.size(); i++)
	{
		for(j = 0; j < pp -> p[0].size(); j++)
		{
			printf("%4d", pp-> p[i][j]);
		}
		cout << endl;
	}
}
